@extends('admin.layouts.header_other')
@section('title',"后台管理系统")
@section('content')
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
            <li>选项设置</li>
        </ul>
        <div class="layui-tab-content">

            <div class="layui-tab-item layui-show">
                <form class="layui-form" action="">
                    <div class="amin-content">
                        <div class="layui-row layui-col-space15">

                            <div class="layui-col-md9">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">标题</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="title" lay-verify="required|title" value="{{ $result['title'] }}" autocomplete="off" placeholder="请输入 标题" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">副标题</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="subtitle" lay-verify="required|title" value="{{$result['subtitle']}}" autocomplete="off" placeholder="请输入副标题" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">所属分类</label>
                                        <div class="layui-input-inline">
                                            <select name="newcat_id">
                                                <option value="">请选择</option>
                                                @foreach($treeCat as $cat)
                                                    <optgroup label="{{$cat['title']}}">
                                                        @foreach($cat['childer'] as $res)
                                                            <option value="{{$res['id']}}" @if ($res['id']==$result['newcat_id']) selected @endif>{{$res['title']}}</option>
                                                        @endforeach
                                                    </optgroup>
                                                @endforeach

                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">SEO关键字</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="key_seo" lay-verify="pass" value='{{$result['key_seo']}}' placeholder="请输入关键字" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">（多个请用,隔开）</div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">SEO描述</label>
                                    <div class="layui-input-block">
                                        <textarea name="key_description"  class="layui-textarea">{{$result['key_description']}}</textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">SEO简介</label>
                                    <div class="layui-input-block">
                                        <textarea  class="layui-textarea" name="info">{{$result['info']}}</textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">内容</label>
                                    <div class="layui-input-block">
                                        <textarea id="demo" name="content" class="layui-textarea" lay-verify="content" style="display: none;">{{$result['content']}}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md3">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">属性</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="title_attr" title="粗体" value="1" @if ($result['title_attr']==1) checked @endif lay-skin="primary">
                                            <input type="checkbox" name="title_attr" title="斜体" value="2" @if ($result['title_attr']==2) checked @endif lay-skin="primary">
                                            <input type="checkbox" name="title_attr" title="删除线" value="3" @if ($result['title_attr']==3) checked @endif  lay-skin="primary">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">颜色</label>
                                        <div class="layui-input-inline">
                                            <div class="layui-input-inline" style="width: 120px;">
                                                <input type="text" name="title_color" value="{{$result['title_color']}}" placeholder="请选择颜色" class="layui-input" id="test-form-input">
                                            </div>
                                            <div class="layui-inline" style="left: -11px;">
                                                <div id="test-form"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">发布时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="created_at" value="{{$result['created_at']}}" id="date" placeholder="发布时间" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">作者</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="author" value="{{$result['author']}}" lay-verify="required" autocomplete="off" placeholder="作者" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">来源</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="source" value="{{$result['source']}}" lay-verify="required" autocomplete="off" placeholder="来源" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">是否审核</label>
                                        <div class="layui-input-inline">
                                            <input type="radio" name="is_check" value="1" title="审核" checked="">
                                            <input type="radio" name="is_check" value="2" title="待审核">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">外部链接</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="title_url" value="{{$result['title_url']}}" lay-verify="required|title" autocomplete="off" placeholder="外部链接" class="layui-input">
                                        </div>
                                    </div>
                                </div>


                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">推荐</label>
                                        <div class="layui-input-inline">
                                            <select  lay-filter="aihao" name="is_hot">
                                                <option value=""></option>
                                                @foreach($countryInRecommend as $k=>$v)
                                                <option value="{{$k}}" @if ($k==$result['is_hot']) selected @endif>{{$v}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">头条</label>
                                        <div class="layui-input-inline">
                                            <select name="is_first" lay-filter="aihao">
                                                <option value=""></option>
                                                @foreach($countryInFirst as $k=>$v)
                                                <option value="{{$k}}" @if ($k==$result['is_first']) selected @endif>{{$v}}</option>
                                                @endforeach

                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">图片</label>
                                    <div class="layui-inline">
                                        <div class="layui-upload-drag" id="singleUploadImage">
                                            <i id="showimg"><img src="{{$result['images']}}" style="max-width:210px; min-height:136px;" /></i>
                                            <p>点击上传，或将文件拖拽到此处</p>
                                        </div>

                                    </div>
                                    <input type="hidden" id="uploadimages" name="_token" value="{{csrf_token()}}">
                                    <input type="hidden" id="uploadimages_input" name="images" value="{{$result['images']}}">
                                    <input type="hidden" name="id" value="{{$result['id']}}">
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="countryInsubmit">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <div class="layui-form-item">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">是否置顶</label>
                                <div class="layui-input-inline">
                                    <select name="interest" lay-filter="aihao">
                                        <option value=""></option>
                                        <option value="0">推荐</option>
                                        <option value="0">不推荐</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
    <script src="{{asset('attach/js/layui.all.js')}}"></script>
    <script>
        layui.use(['layedit','form','layer'],function () {
            var layedit = layui.layedit;
            var publish_time = layui.laydate;
            var colorpicker  = layui.colorpicker;
            var $ = layui.$
                ,colorpicker = layui.colorpicker;
            var form = layui.form;
            var layer = layui.layer;
            var upload =layui.upload;
            var token =$('#uploadimages22').val();
            upload.render({
                elem: '#singleUploadImage'
                ,url: "{{route('admin.images.uploadimages')}}"
                ,data:{'_token':$("#uploadimages").val()}
                ,auto:true
                ,done: function(res){
                    if(res.code==0){
                        $("#showimg").html('<img src="'+res.data.src+'" style="max-width:210px; min-height:136px;" />');
                        $("#uploadimages_input").val(res.data.id);

                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            colorpicker.render({
                elem: '#test-form' //绑定元素
                ,color:'#1c97f5'
                ,done: function(color){ //颜色改变的回调
                    $("#test-form-input").val(color);
                }
            });
            publish_time.render({
                elem: "#date"
                ,type: 'datetime'
            });
            layedit.set(
                {
                uploadImage: {
                    url: "{{route('admin.images.uploadimages')}}",
                    type: 'post', //默认post
                    data:{_token:token}
                }
            });
            var index =layedit.build('demo',{
                height:300,
                tool:['left','center','right','|','face','link','unlink','image','help','del','strong','italic','underline','attachment','video']
            });
            form.verify({ //提交表单的时候同步内容到 textarea

                content: function(value) {

                    return layedit.sync(index);

                }
            });
            form.on('submit(countryInsubmit)',function (data) {
                var index = parent.layer.getFrameIndex(window.name);
                var url='{{route('admin.countryin.editsave')}}',
                    data=$(data.form).serialize();
                $.ajax({
                    type:'POST',
                    url:url,
                    data:data,
                    success:function (data) {
                        if(data.code==200){
                            layer.msg(data.msg,{
                                icon:6,
                                time:2000
                            },function () {
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                        }else{
                            layer.msg(data.msg,{icon:5});
                            return;
                        }
                    },
                    complete:function () {
                        layer.close(this.layerIndex)
                    }
                })
                return false;
            })
        });
    </script>
@endsection
